#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/core/core.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main() {
    VideoCapture capture(1);
    capture.set(CV_CAP_PROP_FRAME_WIDTH,1920);
    capture.set(CV_CAP_PROP_FRAME_HEIGHT,1080);
    capture.set(CV_CAP_PROP_FPS,30);
    Mat frame;
    string frameSavePath = "../saveImg/ ";
    int i = 0;
    while (capture.isOpened()) {
        capture >> frame;
        if (frame.empty()) {
            cout << "frame is empty" << endl;
        }
        double t1 = getTickCount();
        cv::Mat imgShow = frame.clone();
        double t2 = (getTickCount()-t1)*1000/getTickFrequency();
        resize(imgShow,imgShow,Size(0, 0), 0.3, 0.3);
        namedWindow("video",WINDOW_NORMAL);
        imshow("video", imgShow);
        char key_board = waitKey(10);
        if (key_board == 's') {
            ostringstream imgName;
            imgName << i << ".jpg";
            cout << i << ".jpg " << "saved" << endl;
            imwrite(frameSavePath + imgName.str(), frame);
            i++;
        }
        else if(key_board == -1){
        	continue;        	
        }
        else{
        	break;
        }
    }
}